﻿#include "stdafx.h"
#include "网格处理.h"

#include <B_几何图形/三角形.h>
#include <ppl.h>
#include <面/面.h>

using namespace std;



void f_vec2_阵列(vector<vec2>& 目标, const vector<vec2>& 源, uint32 阵列数量) {
	uint32 oldNum = 源.size();
	const vec2* oldVP = 源.data();

	目标.resize(oldNum * 阵列数量);
	vec2* vp = 目标.data();

	Concurrency::parallel_for<uint32>(0, 阵列数量, [&](uint32 i) {
		uint32 startID = i * oldNum;
#pragma loop(no_vector)
		for (uint32 j = 0; j < oldNum; ++j) {
			vp[startID + j] = oldVP[j];
		}
	});

/*#pragma loop(no_vector)
	for (uint32 i = 0; i < 阵列数量; ++i) {
		uint32 startID = i * oldNum;
#pragma loop(no_vector)
		for (uint32 j = 0; j < oldNum; ++j) {
			vp[startID + j] = oldVP[j];
		}
	}*/
}



void f_vec3_阵列(vector<vec3>& 目标, const vector<vec3>& 源, uint32 阵列数量){
	uint32 oldNum = 源.size();
	const vec3* oldVP = 源.data();

	目标.resize(oldNum * 阵列数量);
	vec3* vp = 目标.data();

	Concurrency::parallel_for<uint32>(0, 阵列数量, [&](uint32 i) {
		uint32 startID = i * oldNum;

		/*Concurrency::parallel_for<uint32>(0, oldNum, [&](uint32 j) {
			vp[startID + j] = oldVP[j];
		});*/
		#pragma loop(no_vector)
		for (uint32 j = 0; j < oldNum; ++j) {
			vp[startID + j] = oldVP[j];
		}
	});

	/*
#pragma loop(no_vector)
	for (uint32 i = 0; i < 阵列数量; ++i) {
		uint32 startID = i * oldNum;
#pragma loop(no_vector)
		for (uint32 j = 0; j < oldNum; ++j) {
			vp[startID + j] = oldVP[j];
		}
	}*/
	
}

void f_uint32索引_阵列(vector<vector<uint32>>& 目标, const vector<vector<uint32>>& 源, uint32 阵列数量, uint32 offset) {
	uint32 oldYNum = 源.size();
	const vector<uint32>* oldVYp = 源.data();


	目标.resize(oldYNum * 阵列数量);
	vector<uint32>* vYp = 目标.data();


	Concurrency::parallel_for<uint32>(0, 阵列数量, [&](uint32 i) {
		uint32 startID = i * oldYNum;

		Concurrency::parallel_for<uint32>(0, oldYNum, [&](uint32 j) {
			vYp[startID + j] = oldVYp[j];

			//偏移计数
			uint32* offsetIndex = vYp[startID + j].data();
			uint32	num = vYp[startID + j].size();
			#pragma loop(no_vector)
			for (uint32 k = 0; k < num; ++k) {
				offsetIndex[k] += offset * i;
			}
		});
/*#pragma loop(no_vector)
		for (uint32 j = 0; j < oldYNum; ++j) {
			vYp[startID + j] = oldVYp[j];

			//偏移计数
			uint32* offsetIndex = vYp[startID + j].data();
			uint32	num = vYp[startID + j].size();
#pragma loop(no_vector)
			for (uint32 k = 0; k < num; ++k) {
				offsetIndex[k] += offset * i;
			}
		}*/
	});

/*#pragma loop(no_vector)
	for (uint32 i = 0; i < 阵列数量; ++i) {
		uint32 startID = i * oldYNum;

#pragma loop(no_vector)
		for (uint32 j = 0; j < oldYNum; ++j) {
			vYp[startID + j] = oldVYp[j];

			//偏移计数
			uint32*	offsetIndex = vYp[startID + j].data();
			uint32	num = vYp[startID + j].size();
#pragma loop(no_vector)
			for (uint32 k = 0; k < num; ++k) {
				offsetIndex[k] += offset*i;
			}
		}
	}*/

}

void f_PyObj_to_uint32_1D(PyObject* 源, vector<uint32>& 目标) {
	uint32 num = PyList_Size(源);

	目标.resize(num);
	uint32* p = 目标.data();

	Concurrency::parallel_for<uint32>(0, num, [&](uint32 i) {
		p[i] = PyLong_AsLong(PyList_GetItem(源, i));
	});
}


void f_PyObj_to_vec2s(PyObject* 源, vector<vec2>& 目标) {
	uint32 num = PyList_Size(源);

	目标.resize(num);
	vec2* p = 目标.data();

#pragma loop(on_vector)
	for (uint32 i = 0; i < num; ++i) {
		PyObject* co = PyList_GetItem(源, i);
		p[i].x = PyFloat_AsDouble(PyTuple_GetItem(co, 0));
		p[i].y = PyFloat_AsDouble(PyTuple_GetItem(co, 1));
	}
}

void f_PyObj_to_vec3s(PyObject * 源, vector<vec3>& 目标) {
	uint32 num = PyList_Size(源);

	目标.resize(num);
	vec3* p = 目标.data();

#pragma loop(on_vector)
	for (uint32 i = 0; i < num; ++i) {
		PyObject* co = PyList_GetItem(源, i);
		p[i].x = PyFloat_AsDouble(PyTuple_GetItem(co, 0));
		p[i].y = PyFloat_AsDouble(PyTuple_GetItem(co, 1));
		p[i].z = PyFloat_AsDouble(PyTuple_GetItem(co, 2));
	}
}

void f_PyObj_to_多边形索引(PyObject* 源, vector<vector<uint32>>& 目标) {
	uint32 y = PyList_Size(源);

	目标.resize(y);
	vector<uint32>* yp = 目标.data();


	Concurrency::parallel_for<uint32>(0, y, [&](uint32 i) {
		PyObject* item = PyList_GetItem(源, i);
		uint32 x = PyList_Size(item);

		yp[i].resize(x);
		uint32* xp = yp[i].data();

#pragma loop(on_vector)
		for (uint32 ix = 0; ix < x; ++ix) {
			xp[ix] = PyLong_AsLong(PyList_GetItem(item, ix));
		}
	});

/*#pragma loop(on_vector)
	for (uint32 iy = 0; iy < y; ++iy) {
		PyObject* item = PyList_GetItem(源, iy);
		uint32 x = PyList_Size(item);
		
		yp[iy].resize(x);
		uint32* xp = yp[iy].data();

#pragma loop(on_vector)
		for (uint32 ix = 0; ix < x; ++ix) {
			xp[ix] = PyLong_AsLong(PyList_GetItem(item, ix));
		}
	}*/
}







void f_顶点索引扁平化(const vector<vector<uint32>>& 源, vector<uvec3>& 目标) {
	uint32 num = 源.size();
	const vector<uint32>* p = 源.data();
	
	目标.resize(num);
	uvec3* r = 目标.data();

	Concurrency::parallel_for<uint32>(0, num, [&](uint32 i) {
		r[i].x = p[i][0];
		r[i].y = p[i][1];
		r[i].z = p[i][2];
	});

}

void f_顶点索引扁平化(const vector<vector<uint32>>& 源, vector<uint32>& 目标) {
	uint32 num = 源.size();
	const vector<uint32>* p = 源.data();

	for (uint32 i = 0; i < num; ++i) {
		uint32 faceNum = p->size();

		for (uint32 j = 0; j < faceNum; ++j) {
			目标.push_back(p[i][j]);
		}
	}
}



void f_计算多边形平滑法线(const vector<vec3>& v, vector<vector<uint32>>& i, vector<vec3>& n) {
	n.resize(v.size());

	//构建BVH

}

void f_顶点BVH构建(const vector<vec3>& v, const vector<vector<uint32>>& i, const vec3* c, float32 dir) {
	vector<uint32> 左;
	vector<uint32> 右;
	vector<uvec2> offset;

	uint32 num = v.size();
	const vec3* point = v.data();

	uint32 iNum = i.size();
	const vector<uint32>* indexPoint = i.data();

	for (uint32 i = 0; i < num; ++i) {
		const uint32* index = indexPoint[i].data();
		//vec3 中心坐标 = f_三角形中心坐标(point[index[0]], point[index[1]], point[index[2]]);

		if (c[i].x >= dir) {
			左.push_back(i);
		} else {
			右.push_back(i);
		}
	}

	//offset.push_back({ 0, 左.size()});
	//offset.push_back({ 左.size(), 右.size() });

	

	for (uint32 i = 0; i < num; ++i) {
		if (point[i].x >= dir) {
			左.push_back(i);
		}
		else {
			右.push_back(i);
		}
	}

}




















void f_创建独立网格插座数量(S_网格插座数据* meshs) {
	/*concurrency::parallel_invoke(
		[&] { meshs->m_顶点 = new vector<vec3>(); },
		[&] { meshs->m_法线 = new vector<vec3>(); },
		[&] { meshs->m_UV1 = new vector<vec2>(); },
		[&] { meshs->m_UV2 = new vector<vec2>(); },
		[&] { meshs->m_面法线 = new vector<vec3>(); },
		[&] { meshs->m_面中心 = new vector<vec3>(); }
	);
	concurrency::parallel_invoke(
		[&] { meshs->m_边索引 = new vector<ivec2>(); },
		[&] { meshs->m_索引 = new vector<vector<uint32>>(); },
		[&] { meshs->m_材质ID = new vector<uint32>(); },

		[&] { meshs->m_多边形 = new vector<ivec2>(); },
		[&] { meshs->m_环 = new vector<ivec2>(); },
		[&] { meshs->m_面面积 = new vector<float32>(); }
	);*/

	meshs->m_顶点	= new vector<vec3>();
	meshs->m_法线	= new vector<vec3>();
	meshs->m_UV1	= new vector<vec2>();
	meshs->m_UV2	= new vector<vec2>();
	meshs->m_面法线 = new vector<vec3>();
	meshs->m_面中心 = new vector<vec3>();

	meshs->m_边索引 = new vector<ivec2>();
	meshs->m_索引 = new vector<vector<uint32>>();
	meshs->m_材质ID = new vector<uint32>();

	meshs->m_多边形 = new vector<ivec2>();
	meshs->m_环		= new vector<ivec2>();
	meshs->m_面面积 = new vector<float32>();

	meshs->m_UV		= new vector<vector<vec2>>();
	meshs->m_材质槽	= new vector<S_材质槽>();

}

void f_释放独立网格插座数量(S_网格插座数据* mesh) {
	if (mesh->m_顶点)	delete mesh->m_顶点;
	if (mesh->m_法线)	delete mesh->m_法线;
	if (mesh->m_UV1)	delete mesh->m_UV1;
	if (mesh->m_UV2)	delete mesh->m_UV2;
	if (mesh->m_面法线)	delete mesh->m_面法线;
	if (mesh->m_面中心) delete mesh->m_面中心;
	if (mesh->m_索引) delete mesh->m_索引;
	if (mesh->m_材质ID) delete mesh->m_材质ID;
	if (mesh->m_多边形) delete mesh->m_多边形;
	if (mesh->m_环)		delete mesh->m_环;
	if (mesh->m_面面积)	delete mesh->m_面面积;
	if (mesh->m_UV)		delete mesh->m_UV;
	if (mesh->m_材质槽)	delete mesh->m_材质槽;


	mesh->m_顶点	= 0;
	mesh->m_法线	= 0;
	mesh->m_UV1		= 0;
	mesh->m_UV2		= 0;
	mesh->m_面法线	= 0;
	mesh->m_面中心	= 0;
	mesh->m_索引	= 0;
	mesh->m_材质ID	= 0;
	mesh->m_多边形	= 0;
	mesh->m_环		= 0;
	mesh->m_面面积	= 0;
	mesh->m_UV		= 0;
	mesh->m_材质槽	= 0;

}





bool f_从Py数据构建网格(S_网格插座数据* mesh, PyObject* item) {
	f_创建独立网格插座数量(mesh);


	PyObject* 顶点 = PyList_GetItem(item, 1);
	PyObject* 法线 = PyList_GetItem(item, 2);
	PyObject* UV = PyList_GetItem(item, 3);
	PyObject* UV坐标 = PyList_GetItem(item, 4);

	PyObject* 索引 = PyList_GetItem(item, 5);
	PyObject* 面法线 = PyList_GetItem(item, 6);
	PyObject* 面中心 = PyList_GetItem(item, 7);

	PyObject* 边 = PyList_GetItem(item, 8);
	PyObject* 环 = PyList_GetItem(item, 9);
	PyObject* 多边形 = PyList_GetItem(item, 10);

	PyObject* 面材质ID = PyList_GetItem(item, 11);
	PyObject* 材质槽 = PyList_GetItem(item, 12);


	





	//C_Vector1D_Vec3插座* vs = DEF_转换为arrayVec3插座(f_get输出插座(1));
	f_PyObj_to_vec3s(顶点, *mesh->m_顶点);
	//C_Vector1D_Vec3插座* ns = DEF_转换为arrayVec3插座(f_get输出插座(2));
	f_PyObj_to_vec3s(法线, *mesh->m_法线);
	//C_Vector1D_Vec3插座* uv1 = DEF_转换为arrayVec3插座(f_get输出插座(2));
	f_PyObj_to_vec2s(UV, *mesh->m_UV1);


	uint32 uvNum = PyList_Size(UV坐标);
	mesh->m_UV->resize(uvNum);
	for (uint32 i = 0; i < uvNum; ++i) {
		PyObject* uvLayout = PyList_GetItem(UV坐标, i);
		f_PyObj_to_vec2s(uvLayout, (*(mesh->m_UV))[i]);
	}



	//C_面顶点索引插座* is = DEF_转换为面顶点索引插座(f_get输出插座("面索引"));
	f_PyObj_to_多边形索引(索引, *mesh->m_索引);
	//C_Vector1D_Vec3插座* fn = DEF_转换为arrayVec3插座(f_get输出插座("面法线"));
	f_PyObj_to_vec3s(面法线, *mesh->m_面法线);
	//C_Vector1D_Vec3插座* fc = DEF_转换为arrayVec3插座(f_get输出插座("面中心"));
	f_PyObj_to_vec3s(面中心, *mesh->m_面中心);

	f_PyObj_to_uint32_1D(面材质ID, *mesh->m_材质ID);




	uint32 材质槽数量 = PyList_Size(材质槽);
	mesh->m_材质槽->resize(材质槽数量);
	for (uint32 i = 0; i < 材质槽数量; ++i) {
		auto& 槽 = (*(mesh->m_材质槽))[i];
		PyObject* 槽项 = PyList_GetItem(材质槽, i);
		槽.m_bl材质 = PyTuple_GetItem(槽项, 0);
		槽.m_材质哈希 = PyLong_AsUnsignedLongLong(PyTuple_GetItem(槽项, 1));
	}



	return true;

}

void f_from网格插座数据填充物体(S_物体* obj, S_网格插座数据& 网格) {
	auto* mesh = f_from物体Mesh(obj);

	mesh->f_fill顶点(*(网格.m_顶点));
	mesh->f_fill法线(*(网格.m_法线));

	std::vector<uint32> i;
	f_顶点索引扁平化(*(网格.m_索引), i);
	//mesh->f_fill索引(i);
}

S_物体* f_from网格插座数据创建物体(S_网格插座数据& 网格) {
	S_物体* obj = f_ob_创建物体(E_物体数据::t_网格, 0, { E_绘图API::E_CUDA, 0,0 });
	f_from网格插座数据填充物体(obj, 网格);
	return obj;
}











void f_变换网格(S_网格插座数据* mesh, C_Mat44& mat) {
	uint32 num	= mesh->m_顶点->size();
	auto* v		= mesh->m_顶点->data();
	auto* n		= mesh->m_法线->data();
	Concurrency::parallel_for<uint32>(0, num, [&](uint32 i) {
		v[i] *= mat;
		n[i] *= mat;
	});
}






S_网格插座数据 f_拷贝网格插座数量(const S_网格插座数据& mesh) {
	S_网格插座数据 data;

	f_创建独立网格插座数量(&data);

	concurrency::parallel_invoke(
		[&] { if (mesh.m_顶点)* (data.m_顶点)		= *(mesh.m_顶点); },
		[&] { if (mesh.m_法线)* (data.m_法线)		= *(mesh.m_法线); },
		[&] { if (mesh.m_UV1) * (data.m_UV1)		= *(mesh.m_UV1); },
		[&] { if (mesh.m_UV2) * (data.m_UV2)		= *(mesh.m_UV2); },
		[&] { if (mesh.m_面法线) * (data.m_面法线)	= *(mesh.m_面法线); },
		[&] { if (mesh.m_面中心) * (data.m_面中心)	= *(mesh.m_面中心); },
		[&] { if (mesh.m_边索引) * (data.m_边索引)	= *(mesh.m_边索引); },
		[&] { if (mesh.m_索引) * (data.m_索引)	= *(mesh.m_索引); },
		[&] { if (mesh.m_材质槽)* (data.m_材质槽)	= *(mesh.m_材质槽); }
	);
	
	concurrency::parallel_invoke(
		[&] { if (mesh.m_多边形) * (data.m_多边形)	= *(mesh.m_多边形); },
		[&] { if (mesh.m_环) * (data.m_环)			= *(mesh.m_环); },
		[&] { if (mesh.m_面面积)* (data.m_面面积)	= *(mesh.m_面面积); },
		[&] { if (mesh.m_材质ID)* (data.m_材质ID)	= *(mesh.m_材质ID); }
	);

	return data;
}







void f_合并材质槽材质(S_网格插座数据& mesh, const vector<S_网格插座数据>& 源meshes) {

}

S_网格插座数据 f_合并网格插座数据(const vector<S_网格插座数据> meshes) {
	//C_线程池 t(meshes.size());
	uint32 num = meshes.size();
	if (!num) return {0};

	S_网格插座数据 newMesh = f_拷贝网格插座数量(meshes[0]);

	uint32 顶点数量Offset	= meshes[0].m_顶点->size();
	uint32 材质IDOffset		= meshes[0].m_材质槽->size();
	for (uint32 i = 1; i < num; ++i) {
		auto& mesh = meshes[i];

		concurrency::parallel_invoke(
			[&] { 
				auto& v_顶点 = (*(mesh.m_顶点));
				if (v_顶点.size()) {
					uint32 offset = newMesh.m_顶点->size();
					uint32 num = mesh.m_顶点->size();
					newMesh.m_顶点->resize(offset + num);

					auto* v_p顶点		= newMesh.m_顶点->data();
					auto* v_p顶点要追加	= mesh.m_顶点->data();
					
					for (uint32 i = 0; i < num; ++i) {
						v_p顶点[i + offset] = v_p顶点要追加[i];
					}
					//*(newMesh.m_顶点)->insert(newMesh.m_顶点->end(), mesh.m_顶点->begin(), mesh.m_顶点->end());
				}
			},
			[&] { 
				auto& v_法线 = (*(mesh.m_法线));
				if (v_法线.size()) {
					uint32 offset = newMesh.m_法线->size();
					uint32 num = mesh.m_法线->size();
					newMesh.m_法线->resize(offset + num);

					auto* v_p法线		= newMesh.m_法线->data();
					auto* v_p法线要追加	= mesh.m_法线->data();

					for (uint32 i = 0; i < num; ++i) {
						v_p法线[i + offset] = v_p法线要追加[i];
					}
					//*(newMesh.m_法线)->insert(newMesh.m_法线->end(), mesh.m_法线->begin(), mesh.m_法线->end());
				}
			},
			[&] { 
				auto& v_UV1 = (*(mesh.m_UV1));
				if (v_UV1.size()){
					uint32 offset = newMesh.m_UV1->size();
					uint32 num = mesh.m_UV1->size();
					newMesh.m_UV1->resize(offset + num);

					auto* v_pUV = newMesh.m_UV1->data();
					auto* v_pUV要追加UV = mesh.m_UV1->data();

					for (uint32 i = 0; i < num; ++i) {
						v_pUV[i + offset] = v_pUV要追加UV[i];
					}
					//*(newMesh.m_UV1)->insert(newMesh.m_UV1->end(), mesh.m_UV1->begin(), mesh.m_UV1->end()); 
				}
			},
			[&] { 
				auto& v_UV2 = (*(mesh.m_UV2));
				if (v_UV2.size()) {
					uint32 offset = newMesh.m_UV2->size();
					uint32 num = mesh.m_UV2->size();
					newMesh.m_UV2->resize(offset + num);

					auto* v_pUV			= newMesh.m_UV2->data();
					auto* v_pUV要追加UV	= mesh.m_UV2->data();

					for (uint32 i = 0; i < num; ++i) {
						v_pUV[i + offset] = v_pUV要追加UV[i];
					}
					//*(newMesh.m_UV2)->insert(newMesh.m_UV2->end(), mesh.m_UV2->begin(), mesh.m_UV2->end());
				}
			},
			[&] { 
				auto& v_面法线 = (*(mesh.m_面法线));
				if (v_面法线.size()) {
					uint32 offset = newMesh.m_面法线->size();
					uint32 num = mesh.m_面法线->size();
					newMesh.m_面法线->resize(offset + num);

					auto* v_p面法线 = newMesh.m_面法线->data();
					auto* v_p要追加面法线 = mesh.m_面法线->data();

					for (uint32 i = 0; i < num; ++i) {
						v_p面法线[i + offset] = v_p要追加面法线[i];
					}
					//*(newMesh.m_面法线)->insert(newMesh.m_面法线->end(), mesh.m_面法线->begin(), mesh.m_面法线->end());
				}
			},
			[&] { 
				auto& v_面中心 = (*(mesh.m_面中心));
				if (v_面中心.size()) {
					uint32 offset = newMesh.m_面中心->size();
					uint32 num = mesh.m_面中心->size();
					newMesh.m_面中心->resize(offset + num);

					auto* v_p面中心			= newMesh.m_面中心->data();
					auto* v_p要追加面中心	= mesh.m_面中心->data();

					for (uint32 i = 0; i < num; ++i) {
						v_p面中心[i + offset] = v_p要追加面中心[i];
					}
					//*(newMesh.m_面中心)->insert(newMesh.m_面中心->end(), mesh.m_面中心->begin(), mesh.m_面中心->end());
				}
			},
			[&] { 
				if (mesh.m_材质ID->size()) {
					*(newMesh.m_材质ID)->insert(newMesh.m_材质ID->end(), mesh.m_材质ID->begin(), mesh.m_材质ID->end());

					uint32 matNum = mesh.m_材质槽->size();
					auto* matSocket = mesh.m_材质槽->data();

					vector<uvec2> 材质ID映射(matNum);
					uint32 材质IDOffset叠加 = 0;
					for (uint16 j = 0; j < matNum; ++j) {
						材质ID映射[j] = { j, j + 材质IDOffset };

						uint64 材质组当前槽哈希 = matSocket[j].m_材质哈希;

						bool 是否没有映射 = true;
						uint32 以存在材质槽数量 = newMesh.m_材质槽->size();
						auto* 以存在材质槽 = newMesh.m_材质槽->data();
						for (uint32 k = 0; k < 以存在材质槽数量; ++k) {
							auto& 以存在对比项 = 以存在材质槽[k];

							if (材质组当前槽哈希 == 以存在对比项.m_材质哈希) {
								材质ID映射[j].y = k;
								是否没有映射 = false;
								break;
							}
						}
						
						if (是否没有映射) {
							newMesh.m_材质槽->push_back(matSocket[j]);

							++材质IDOffset叠加;
						}

					}
					材质IDOffset += 材质IDOffset叠加;


					uint32 要加入的材质IDnum = mesh.m_材质ID->size();
					vector<uint32> tempMatID(要加入的材质IDnum);
					auto* soundID = mesh.m_材质ID->data();
					auto* mapID = 材质ID映射.data();

					auto 已有材质ID数量 = newMesh.m_材质ID->size() - 要加入的材质IDnum;
					//newMesh.m_材质ID->resize(已有材质ID数量 + 要加入的材质IDnum);
					auto* p新材质ID = newMesh.m_材质ID->data();
					for (uint32 j = 0; j < 要加入的材质IDnum; ++j) {
						auto 材质ID = soundID[j];
						for (uint16 k = 0; k < matNum; ++k) {
							if (材质ID == mapID[k].x) {
								材质ID = mapID[k].y;
								break;
							}
						}

						p新材质ID[已有材质ID数量 + j] = 材质ID;
					}
				}
			}
		);
	};


	for (uint32 i = 1; i < num; ++i) {
		auto& mesh = meshes[i];
		
		
		concurrency::parallel_invoke(
			[&] {
				auto& edge = *(mesh.m_边索引);
				uint32 vNum = edge.size();

				if (vNum) {
					auto& v_边索引 = (*(newMesh.m_边索引));

					uint32 offset = v_边索引.size();
					v_边索引.resize(offset + vNum);

					auto* v_p边索引 = v_边索引.data();
					auto* v_pE1 = edge.data();
					/*Concurrency::parallel_for<uint32>(0, vNum, [&](uint32 y) {
						ep1[y].x += 顶点数量Offset;
						ep1[y].y += 顶点数量Offset;
					});*/
					for (uint32 y = 0; y < vNum; ++y) {
						//ep1[y].x += 顶点数量Offset;
						//ep1[y].y += 顶点数量Offset;

						v_p边索引[y + offset].x = v_pE1[y].x + 顶点数量Offset;
						v_p边索引[y + offset].y = v_pE1[y].y + 顶点数量Offset;
					}
					//*(newMesh.m_边索引)->insert(newMesh.m_边索引->end(), edge.begin(), edge.end());
				}
			},
			[&] {
				auto& index = *(mesh.m_索引);
				uint32 iNum = index.size();

				if (iNum) {
					auto& v_面索引 = (*(newMesh.m_索引));

					uint32 offset = v_面索引.size();
					v_面索引.resize(offset + iNum);

					auto* v_p面索引 = v_面索引.data();
					auto* v_pI1 = index.data();
					//auto* ip1 = index.data();
					//Concurrency::parallel_for<uint32>(0, iNum, [&](uint32 y) {
					//	for (auto& yi : ip1[y]) yi += 顶点数量Offset;
					//});
					for (uint32 y = 0; y < iNum; ++y) {
						uint16 面顶点数 = v_pI1[y].size();
						v_p面索引[y + offset].resize(面顶点数);

						auto* v_p面顶点索引			= v_p面索引[y + offset].data();
						auto* v_p面顶点索引要赋予	= v_pI1[y].data();
						for (uint16 j = 0; j < 面顶点数; ++j) {
							v_p面顶点索引[j] = v_p面顶点索引要赋予[j] + 顶点数量Offset;
						}
						//for (auto& yi : v_👈ip1[y]) yi += 顶点数量Offset;
					}
					//*(newMesh.m_索引)->insert(newMesh.m_索引->end(), index.begin(), index.end());
				}
			}
		);

		顶点数量Offset += mesh.m_顶点->size();

	}

	return newMesh;
}








